const fs = require('fs')
const path = require('path')

function renameComponent(oldName, newName) {
    const oldPath = path.resolve(__dirname, 'src/views', oldName + '.vue')
    const newPath = path.resolve(__dirname, 'src/views', newName + '.vue')
    fs.renameSync(oldPath, newPath)
    console.log(`Renamed ${oldName}.vue → ${newName}.vue`)
}

function updateImportsInFile(file, oldName, newName) {
    let content = fs.readFileSync(file, 'utf-8')
    content = content.replace(new RegExp(oldName, 'g'), newName)
    fs.writeFileSync(file, content)
    console.log(`Updated imports in ${file}`)
}

// 重命名组件文件
renameComponent('Login', 'LoginPage')
renameComponent('Welcome', 'WelcomePage')

// 更新路由引用
updateImportsInFile('src/router/index.js', 'Login', 'LoginPage')
updateImportsInFile('src/router/index.js', 'Welcome', 'WelcomePage')
